function [ civil_stat, replacements_mar ] = matching( CivilStatues, Marriage)

ll = length(CivilStatues);
civil_stat = cell(ll,1);
replacements_mar = zeros(ll,1);
n = length(Marriage);

%%%%%%%%%%%% We look for the first matches from the existing list %%%%%%%%%%%%%%%%%%%%

for k = 2:n
    
    for i = 1:ll
        
        q = findstr(Marriage{k,1},CivilStatues{i,1});
        
        if length(q)~= 0
            
            civil_stat{i,1} = Marriage{k,1};
            replacements_mar(i,1) = replacements_mar(i,1) + 1;
            
        end
            
    end
    
end

%%%%%%%%%%%% Here we look for the ones who are not matched yet but with a distance to word that is very close %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Meaning some words have a small typo, and we correct for that after having matched the ones accurately transcribed %%%%%%%%%%%%%%%%%%%%

for k = 2:n
    
    for i = 1:ll

        if (EditDistance(Marriage{k,1},CivilStatues{i,1}) < 2) && (replacements_mar(i,1) == 0)
            
            replacements_mar(i,1) = replacements_mar(i,1) + 1;
            civil_stat{i,1} = Marriage{k,1};
        end
    end
end

for j = 1:ll
    
if length(CivilStatues{j,1}) == 0
    
    civil_stat{j,1} = Marriage{1,1};
    replacements_mar(j,1) = replacements_mar(j,1) + 1;
    
end
end



%%%%%%%%%%%%%%%%%%%%%%%%%%% Not treated %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for j = 1:ll
    
if length(civil_stat{j,1}) == 0
    
    civil_stat{j,1} = 'to be filled';
    replacements_mar(j,1) = replacements_mar(j,1) + 1;
    
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

replacements_mar = num2cell(replacements_mar);

end



